package com.qys.livesMall.system.controller.sys;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qys.livesMall.common.exception.QysException;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.framework.view.BaseQuery;
import com.qys.livesMall.system.enums.SystemMessageEnum;
import com.qys.livesMall.system.model.dto.sys.PlatformNewsDto;
import com.qys.livesMall.system.model.vo.sys.PlatformInfoVO;
import com.qys.livesMall.system.model.vo.sys.PlatformNewsVO;
import com.qys.livesMall.system.service.PlatformNewsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 平台新闻发布 前端控制器
 * </p>
 *
 * @author
 * @since 2023-08-29
 */
@RestController
@RequestMapping("sys/platformNews")
@Tag(name = "sys-平台新闻发布", description = "sys-平台新闻发布")
public class SysPlatformNewsController {

    @Resource
    private PlatformNewsService platformNewsService;

    @Operation(summary = "添加平台新闻")
    @PostMapping("/add")
    public R add(@RequestBody @Validated PlatformNewsDto dto){
        return platformNewsService.add(dto)? R.ok():R.fail();
    }

    @Operation(summary = "修改平台新闻")
    @PostMapping("/update")
    public R update(@RequestBody @Validated PlatformNewsDto dto){
        if (null == dto.getId()){
            throw new QysException(SystemMessageEnum.SYSTEM_NOT_ID);
        }
        return platformNewsService.updateInfo(dto)? R.ok():R.fail();
    }

    @Operation(summary = "删除平台新闻")
    @DeleteMapping(value = "/delete/{id}")
    public R delete(@PathVariable Long id){
        platformNewsService.removeById(id);
        return R.ok();
    }

    @Operation(summary = "查询平台新闻列表")
    @PostMapping("query")
    public R<IPage<PlatformNewsVO>> query(@RequestBody @Validated BaseQuery dto){
        return R.ok(platformNewsService.query(dto));
    }

    @Operation(summary = "查询平台新闻详情")
    @GetMapping(value = "/info/{id}")
    public R<PlatformNewsVO> info(@PathVariable Long id){
        return R.ok(platformNewsService.info(id));
    }


    @Operation(summary = "平台新闻修改状态")
    @PostMapping("/updateState")
    public R updateState(@RequestBody @Validated PlatformNewsDto dto){
        if (null == dto.getId()){
            throw new QysException(SystemMessageEnum.SYSTEM_NOT_ID);
        }
        return platformNewsService.updateState(dto)? R.ok():R.fail();
    }
}
